﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Root.master" AutoEventWireup="true" CodeFile="OrderH.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxFormLayout" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Xpo.v12.2.Web, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Xpo" TagPrefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content" runat="Server">
    <script type="text/javascript">
        // <![CDATA[
        function ShowLoginWindow() {
            pcEdit.Show();
        }
        function OnSelectedIndexChanged(s, e, visibleIndex) {
            var cbb_house = eval('cbb_house_' + visibleIndex);
            cbb_house.PerformCallback(s.GetValue());
        }
        function StreetCombo_SelectedIndexChanged(s, e) {
            grd1.GetEditor("HOUSE").PerformCallback(s.GetValue());
        }
        function displ(s) {
            var comboText = s.GetText();
            var comboValue = s.GetValue();

            grd1.GetEditor("STREET").PerformCallback(s.GetValue());

            //ds_house.SelectParameters[0].DefaultValue = comboValue;
            // cbb_house.PerformCallback(s.GetValue());
            //alert(comboText);
            // alert(comboValue);
            //ds_house.DataBind();
            //txtCommentsClientName.SetText(comboText);
            //or
            //txtCommentsClientName.SetText(comboValue);
        }

        function ClearCookie() {
            //debugger;
            ASPxClientUtils.DeleteCookie("Ordergrd1");
            grd1.Refresh();
            window.location.reload();
        }
        // ]]> 
    </script>
    <dx:ASPxFormLayout ID="ASPxFormLayout1" runat="server">
        <Items>
            <dx:LayoutGroup Caption="Фильтр" ColCount="4">
                <Items>
                    <dx:LayoutItem Caption="Контрагент">
                        <LayoutItemNestedControlCollection>
                            <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                <dx:ASPxComboBox ID="cbb_kontr" runat="server" DataSourceID="ds_kontr" TextField="NAME" ValueField="CODE" ValueType="System.Int32" IncrementalFilteringMode="StartsWith">
                                    <ValidationSettings Display="Dynamic">
                                        <RequiredField IsRequired="True" />
                                    </ValidationSettings>
                                </dx:ASPxComboBox>
                            </dx:LayoutItemNestedControlContainer>
                        </LayoutItemNestedControlCollection>
                    </dx:LayoutItem>
                    <dx:LayoutItem Caption="Период с:">
                        <LayoutItemNestedControlCollection>
                            <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                <dx:ASPxDateEdit ID="dt1" runat="server" Width="120" Date="2013-04-25" ClientInstanceName="dt1" DateOnError="Today" ValidateRequestMode="Enabled">
                                    <ValidationSettings ErrorTextPosition="Right" ErrorText="  " Display="Dynamic">
                                        <RequiredField IsRequired="true" />
                                    </ValidationSettings>

                                </dx:ASPxDateEdit>
                            </dx:LayoutItemNestedControlContainer>
                        </LayoutItemNestedControlCollection>
                    </dx:LayoutItem>
                    <dx:LayoutItem Caption="по:">
                        <LayoutItemNestedControlCollection>
                            <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                <dx:ASPxDateEdit ID="dt2" runat="server" Date="2013-04-26" Width="120px" ValidationSettings-Display="Dynamic">
                                    <ValidationSettings ErrorTextPosition="Right" ErrorText="  ">
                                        <RequiredField IsRequired="true" />
                                    </ValidationSettings>
                                </dx:ASPxDateEdit>
                            </dx:LayoutItemNestedControlContainer>
                        </LayoutItemNestedControlCollection>
                    </dx:LayoutItem>
                    <dx:LayoutItem Caption="Layout Item" ShowCaption="False">
                        <LayoutItemNestedControlCollection>
                            <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                <dx:ASPxButton ID="btn_Exec" runat="server" OnClick="btn_Exec_Click" Text="Сформировать">
                                </dx:ASPxButton>
                            </dx:LayoutItemNestedControlContainer>
                        </LayoutItemNestedControlCollection>
                    </dx:LayoutItem>
                </Items>
            </dx:LayoutGroup>
            <dx:LayoutGroup Caption="Layout Group" ShowCaption="False">
                <Items>
                    <dx:LayoutItem Caption="button" ShowCaption="False">
                        <LayoutItemNestedControlCollection>
                            <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                <table>
                                    <tr>
                                        <td>
                                            <dx:ASPxButton ID="btn_add" runat="server" AutoPostBack="False" OnClick="btn_add_Click" ToolTip="Добавить наряд">
                                                <Image Url="~/Content/Images/edit1.png">
                                                </Image>
                                            </dx:ASPxButton>
                                        </td>
                                        <td>
                                            <dx:ASPxButton ID="btn_edit" runat="server" OnClick="btn_edit_Click" AutoPostBack="false" ToolTip="Редактировать наряд">
                                                <Image Url="~/Content/Images/edit.png">
                                                </Image>
                                            </dx:ASPxButton>
                                        </td>
                                        <td>
                                            <dx:ASPxButton ID="btn_delete" runat="server" AutoPostBack="False" ToolTip="Удалить наряд">
                                                <Image Url="~/Content/Images/delete.png">
                                                </Image>
                                            </dx:ASPxButton>
                                        </td>
                                        <td>
                                            <dx:ASPxButton ID="btn_print" runat="server" ToolTip="Печать наряда" UseSubmitBehavior="False" Visible="False">
                                                <Image Url="~/Content/Images/print.png">
                                                </Image>
                                            </dx:ASPxButton>
                                        </td>
                                        <td>
                                            <dx:ASPxButton ID="btn_AutoAdd" runat="server" ToolTip="Автосоздание нарядов" UseSubmitBehavior="False" Visible="False">
                                                <ClientSideEvents Click="function(s, e) {
	                                        ClearCookie();
                                        }" />
                                                <Image Url="~/Content/Images/copy.png">
                                                </Image>
                                            </dx:ASPxButton>
                                            
                                        </td>
                                        <td><asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label></td>
                                    </tr>
                                </table>
                            </dx:LayoutItemNestedControlContainer>
                        </LayoutItemNestedControlCollection>
                    </dx:LayoutItem>
                </Items>
            </dx:LayoutGroup>
        </Items>
    </dx:ASPxFormLayout>

    <asp:SqlDataSource ID="ds_WorkList" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringDez %>" DeleteCommand="DELETE FROM &quot;WORKLIST&quot; WHERE &quot;CODE&quot; = ?"
        InsertCommand="INSERT INTO &quot;WORKLIST&quot; (&quot;CODE&quot;, &quot;DATA&quot;, &quot;KONTRAGENT&quot;, &quot;NOTE&quot;, &quot;HOUSE&quot;) VALUES (?, ?, ?, ?, ?)" ProviderName="<%$ ConnectionStrings:ConnectionStringDez.ProviderName %>" SelectCommand="SELECT W.CODE, W.DATA, W.KONTRAGENT, W.NOTE, W.HOUSE, h.STREET, wr.PIPLE FROM WORKLIST W LEFT OUTER JOIN house h ON h.CODE = W.HOUSE LEFT OUTER JOIN mhouse mh ON mh.house = W.HOUSE AND mh.kontragent = W.KONTRAGENT LEFT OUTER JOIN worker wr ON wr.code = mh.worker WHERE (W.DATA BETWEEN @d1 AND @d2) AND (W.KONTRAGENT = @kontr)"
        UpdateCommand="UPDATE &quot;WORKLIST&quot; SET &quot;DATA&quot; = ?, &quot;KONTRAGENT&quot; = ?, &quot;NOTE&quot; = ?, &quot;HOUSE&quot; = ? WHERE &quot;CODE&quot; = ?" ConflictDetection="CompareAllValues" OldValuesParameterFormatString="original_{0}" OnInserting="ds_WorkList_Inserting" OnUpdating="ds_WorkList_Updating">
        <DeleteParameters>
            <asp:Parameter Name="original_CODE" Type="Int32" />
            <asp:Parameter Name="original_DATA" Type="DateTime" />
            <asp:Parameter Name="original_KONTRAGENT" Type="Int32" />
            <asp:Parameter Name="original_NOTE" Type="String" />
            <asp:Parameter Name="original_NOTE" Type="String" />
            <asp:Parameter Name="original_HOUSE" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="CODE" Type="Int32" />
            <asp:Parameter Name="DATA" Type="DateTime" />
            <asp:Parameter Name="KONTRAGENT" Type="Int32" />
            <asp:Parameter Name="NOTE" Type="String" />
            <asp:Parameter Name="HOUSE" Type="Int32" />
        </InsertParameters>
        <SelectParameters>
            <asp:Parameter DefaultValue="" Name="d1" Type="DateTime" />
            <asp:Parameter DefaultValue="" Name="d2" Type="DateTime" />
            <asp:Parameter Name="kontr" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="DATA" Type="DateTime" />
            <asp:Parameter Name="KONTRAGENT" Type="Int32" />
            <asp:Parameter Name="NOTE" Type="String" />
            <asp:Parameter Name="HOUSE" Type="Int32" />
            <asp:Parameter Name="original_CODE" Type="Int32" />
            <asp:Parameter Name="original_DATA" Type="DateTime" />
            <asp:Parameter Name="original_KONTRAGENT" Type="Int32" />
            <asp:Parameter Name="original_NOTE" Type="String" />
            <asp:Parameter Name="original_NOTE" Type="String" />
            <asp:Parameter Name="original_HOUSE" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

    <dx:ASPxPopupControl ID="pcEdit" runat="server" CloseAction="CloseButton" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" ClientInstanceName="pcEdit"
        AllowDragging="True" AllowResize="True" PopupAnimationType="None" EnableViewState="False"
        Width="400px" Height="400px" ShowFooter="True">
        <ContentCollection>
            <dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True">
                <dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="ASPxButton">
                    <ClientSideEvents Click="function(s, e) {}" />
                </dx:ASPxButton>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <dx:ASPxGridView ID="grd1" runat="server" AutoGenerateColumns="False" KeyboardSupport="True" KeyFieldName="CODE" ClientInstanceName="grd1" OnCellEditorInitialize="grd1_CellEditorInitialize">
        <Columns>
            <dx:GridViewCommandColumn VisibleIndex="0" Visible="False">
            </dx:GridViewCommandColumn>
            <dx:GridViewDataHyperLinkColumn Caption="Код" FieldName="CODE" ReadOnly="True" VisibleIndex="1" Width="80px">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/So/OrderSpec.aspx?CODE={0}" TextField="CODE" Target="_blank">
                </PropertiesHyperLinkEdit>
                <EditFormSettings Visible="False" />
            </dx:GridViewDataHyperLinkColumn>
            <dx:GridViewDataDateColumn FieldName="DATA" VisibleIndex="2" Caption="Дата" Width="90px">
                <PropertiesDateEdit Width="150px">
                    <ValidationSettings Display="Dynamic">
                        <RequiredField IsRequired="True" />
                    </ValidationSettings>
                </PropertiesDateEdit>
                <Settings AllowHeaderFilter="False" />
            </dx:GridViewDataDateColumn>
            <dx:GridViewDataComboBoxColumn Caption="Контрагент" FieldName="KONTRAGENT" Name="Kontragrnt" VisibleIndex="3" Width="150px">
                <PropertiesComboBox DataSourceID="ds_kontr" Width="250px"
                    EnableCallbackMode="true" CallbackPageSize="10"
                    IncrementalFilteringMode="Contains" FilterMinLength="3"
                    TextField="NAME" ValueField="CODE" ValueType="System.Int32">
                    <DropDownButton Visible="false" Enabled="False"></DropDownButton>
                    <ValidationSettings>
                        <RequiredField IsRequired="True" />
                    </ValidationSettings>
                </PropertiesComboBox>
                <EditFormSettings Visible="False" />
            </dx:GridViewDataComboBoxColumn>

<dx:GridViewDataComboBoxColumn FieldName="STREET" VisibleIndex="4" Caption="Улица" Width="150px">
                <PropertiesComboBox DataSourceID="ds_street" Width="250px" 
                    IncrementalFilteringMode="StartsWith" EnableCallbackMode="true" CallbackPageSize="20"
                    TextField="NAME" ValueField="CODE" ValueType="System.Int32">
                    <ClientSideEvents SelectedIndexChanged="StreetCombo_SelectedIndexChanged" />
                    <DropDownButton Visible="true" Enabled="true"></DropDownButton>
                </PropertiesComboBox>
                
            </dx:GridViewDataComboBoxColumn>

            <dx:GridViewDataComboBoxColumn Caption="Дом" FieldName="HOUSE" VisibleIndex="6" Width="60px">
                <PropertiesComboBox DataSourceID="AllHouse" Width="150px" 
                    TextField="NOMER" ValueField="CODE" ValueType="System.Int32" 
                    EnableCallbackMode="true" CallbackPageSize="30" 
                    IncrementalFilteringMode="StartsWith">

                    <ValidationSettings Display="Dynamic">
                        <RequiredField IsRequired="True" />
                    </ValidationSettings>
                    <DropDownButton Visible="false" Enabled="False"></DropDownButton>
                </PropertiesComboBox>
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataTextColumn Caption="Примечание" FieldName="NOTE" VisibleIndex="14" Width="250px">
                <PropertiesTextEdit Width="250px">
                </PropertiesTextEdit>
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataComboBoxColumn Caption="Мастер" FieldName="PIPLE" VisibleIndex="12" Width="250px">
                <PropertiesComboBox DataSourceID="ds_piple" TextField="FIO" ValueField="CODE" IncrementalFilteringMode="StartsWith">
                    <DropDownButton Visible="false" Enabled="False"></DropDownButton>
                </PropertiesComboBox>
                <EditFormSettings Visible="False" />
            </dx:GridViewDataComboBoxColumn>
        </Columns>
        <SettingsBehavior AllowFocusedRow="True" AllowSelectByRowClick="True" ColumnResizeMode="Control" EnableCustomizationWindow="True" ConfirmDelete="true" />
        <SettingsPager PageSize="30">
            <PageSizeItemSettings Visible="True">
            </PageSizeItemSettings>
        </SettingsPager>
        <SettingsEditing EditFormColumnCount="1" Mode="EditForm" />
        <Settings ShowFilterBar="Auto" ShowHeaderFilterButton="True" />
        <SettingsCookies Enabled="true" CookiesID="Ordergrd1" StoreControlWidth="True" />
    </dx:ASPxGridView>
    <asp:SqlDataSource ID="AllHouse" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringDez %>" ProviderName="<%$ ConnectionStrings:ConnectionStringDez.ProviderName %>" SelectCommand="SELECT &quot;CODE&quot;, &quot;NOMER&quot; FROM &quot;HOUSE&quot;"></asp:SqlDataSource>
    <asp:SqlDataSource ID="ds_street" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringDez %>" ProviderName="<%$ ConnectionStrings:ConnectionStringDez.ProviderName %>" SelectCommand="SELECT &quot;CODE&quot;, &quot;NAME&quot; FROM &quot;STREET&quot; ORDER BY &quot;NAME&quot;" EnableCaching="True"></asp:SqlDataSource>
    <asp:SqlDataSource ID="ds_house" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringDez %>" ProviderName="<%$ ConnectionStrings:ConnectionStringDez.ProviderName %>"
        SelectCommand="SELECT CODE, NOMER FROM HOUSE WHERE (STREET = ?)">
        <SelectParameters>
            <asp:Parameter Name="STREET" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="ds_piple" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringDez %>" ProviderName="<%$ ConnectionStrings:ConnectionStringDez.ProviderName %>" SelectCommand="select CODE, (f||' '||i||' '||o) FIO from PIPLE"></asp:SqlDataSource>
    <asp:SqlDataSource ID="ds_kontr" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringDez %>" ProviderName="<%$ ConnectionStrings:ConnectionStringDez.ProviderName %>" SelectCommand="SELECT &quot;CODE&quot;, &quot;NAME&quot; FROM &quot;KONTRAGENT&quot; ORDER BY &quot;NAME&quot;"></asp:SqlDataSource>
</asp:Content>

